package com.weslide.weslideapp.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.weslide.weslideapp.fragment.MyExchangeRecord;
import com.weslide.weslideapp.pojo.ao.ExchangeRecodeItemAO;
import com.weslide.weslideapp.pojo.ao.MyExchangeRecordAO;

public class GetExchangeRecordParser {
	private MyExchangeRecordAO record = new MyExchangeRecordAO();

	public void parser(String jsonString) throws JSONException {
		JSONArray jsonArray = new JSONArray(jsonString);
		JSONObject statusJsonObject = jsonArray.getJSONObject(0);
		record.setStatus(statusJsonObject.getString("status"));
		if (record.getStatus().equals("1")) {
			for (int i = 1; i < jsonArray.length(); i++) {
				ExchangeRecodeItemAO ao = new ExchangeRecodeItemAO();
				JSONObject dataJsonObject = jsonArray.getJSONObject(i);
				ao.setExchangeStatus(dataJsonObject.getString("status"));
				ao.setGoodId(dataJsonObject.getString("good_id"));
				ao.setGoodName(dataJsonObject.getString("good_name"));
				ao.setOrderId(dataJsonObject.getString("order_id"));
				ao.setPhone(dataJsonObject.getString("phone"));
				ao.setScore(dataJsonObject.getString("score"));
				ao.setTcount(dataJsonObject.getString("tcount"));
				record.addRecode(ao);
			}
		}
	}

	public MyExchangeRecordAO getData() {
		return record;
	}
}
